package com.sxwl.web.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.sxwl.utils.JsonData;
import com.sxwl.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.sxwl.web.entity.MenuEntity;
import com.sxwl.web.service.MenuService;



/**
 * 
 *
 * @author reading
 * @email 996109719@qq.com
 * @date 2020-05-03 22:21:37
 */
@RestController
@RequestMapping("web/menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public JsonData list(@RequestParam Map<String, Object> params){
        PageUtils page = menuService.queryPage(params);

        return JsonData.success(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public JsonData info(@PathVariable("id") Long id){
		MenuEntity menu = menuService.getById(id);

        return JsonData.success();
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    public JsonData save(@RequestBody MenuEntity menu){
		menuService.save(menu);
        return JsonData.success();
    }

    /**
     * 获取
     */
    @GetMapping("/tree")
    public JsonData getTree(){
       List<MenuEntity> entityList= menuService.getTree();
        return JsonData.success(entityList);
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public JsonData update(@RequestBody MenuEntity menu){
		menuService.updateById(menu);

        return JsonData.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public JsonData delete(@RequestBody Long[] ids){
		menuService.removeByIds(Arrays.asList(ids));
        return JsonData.success();
    }

}
